package com.enjoyor.soa.traffic.rest.tsms.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tsms.RltRouteDeviceDto;
import com.enjoyor.soa.traffic.api.dto.tsms.RltRoutePostDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.IRltRoutePostConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth 
@RestController
@RequestMapping({ "/rltPost" })
@Api("RltRoutePostController相关api")
@CrossOrigin
public class RltRoutePostController {

	@Autowired
	private IRltRoutePostConsumeService iRltRoutePostConsumeService;
	
	/**
	 * 获取岗位分页；
	 * @return zyh
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
    @GetMapping(value = { "/getPostInfoPage" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation(value = "岗位信息分页", notes = "岗位信息分页")
    	@ApiImplicitParams({
        @ApiImplicitParam(name = "postId", value = "岗位编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "taskId", value = "任务编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "isHandle", value = "勤务是否受理", paramType = "query", dataType = "string")})
    public ResultPojo getPostInfoPage(
			@RequestParam(defaultValue = "") String postId,
			@RequestParam(defaultValue = "") String taskId, 
			@RequestParam(defaultValue = "") String routeId, 
			@RequestParam(defaultValue = "") String isHandle, 
    		Page page, HttpServletRequest request){
    	ResultPojo resultPojo = new ResultPojo();
    	resultPojo = iRltRoutePostConsumeService.getRouteRltPostPage(page, taskId, routeId, postId, isHandle);
    	return resultPojo;
    }
	/**
	 * 获取岗位list；
	 * @return zyh
	 */
	@GetMapping(value = { "/getPostInfoList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response=RltRoutePostDto.class, code = 0, message = "")
    @ApiOperation("岗位信息List查询")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "postId", value = "岗位编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "taskId", value = "任务编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "isHandle", value = "勤务是否受理", paramType = "query", dataType = "string")})
	public ResultPojo getPostInfoList( 
			@RequestParam(defaultValue = "") String postId,
			@RequestParam(defaultValue = "") String taskId, 
			@RequestParam(defaultValue = "") String routeId, 
			@RequestParam(defaultValue = "") String isHandle, 
    		HttpServletRequest request) {
		return iRltRoutePostConsumeService.getRouteRltPostList(taskId, routeId, postId, isHandle);
	}
	
	/**
	 * 添加岗位信息(单条)；
	 * @return zyh
	 */
	@PostMapping(value = { "/addRltRoutePost" }, consumes = { "application/json; charset=UTF-8" }, produces = {
	"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加岗位信息(单条)")
	public ResultPojo addRltRoutePost(@RequestBody RltRoutePostDto rltRoutePostDto, HttpServletRequest request) {
		return iRltRoutePostConsumeService.insertRouteRltPost(rltRoutePostDto,((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 修改岗位信息(单条)；
	 * @return zyh
	 */
	@PutMapping(value = { "/editRltRoutePost" }, consumes = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改岗位信息(单条)")
	public ResultPojo editRltRoutePost(@RequestBody RltRoutePostDto rltRoutePostDto, HttpServletRequest request) {
		return iRltRoutePostConsumeService.updateRouteRltPost(rltRoutePostDto,((UserDto) request.getAttribute("currentUser")).getPersonName());	
	}
	
	/**
	 * 删除岗位信息(单条)；
	 * @return zyh
	 */
	@DeleteMapping(value = { "/delRltRoutePost" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除岗位信息(单条)")
    @ApiImplicitParam(name = "postId", value = "岗位编号", paramType = "query", required = true, dataType = "String")
    public ResultPojo delRltRoutePost(
    		@RequestParam(defaultValue = "",value="postId", required=true) String postId,
    		HttpServletRequest request) {
        return iRltRoutePostConsumeService.deleteRouteRltPost(postId, ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	
	/**
	 * 线路关联岗位
	 * @return zyh
	 */
	
	@PostMapping(value = { "/rltRoutePostList" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody   
    @ApiOperation("线路关联岗位")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "taskId", value = "任务编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "rltPostList", value = "关联岗位信息", paramType = "body", dataType = "List<RltRoutePostDto>") })
    public ResultPojo rltRoutePostList(
			@RequestParam(defaultValue = "", value="taskId", required=true) String taskId,
			@RequestParam(defaultValue = "", value="routeId", required=false) String routeId,
			@RequestBody List<RltRoutePostDto> rltPostList, HttpServletRequest request) {
		return iRltRoutePostConsumeService.rltRoutePostList(rltPostList, taskId, routeId,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
}
